package sun.curriculumschedule;

import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by JohnSun on 2016/1/28.
 */


    public class CalendarUtil {

//    public final static int  Monday=1;
//    public final static int  Tuesday=2;
//    public final static int  Wednesday=3;
//    public final static int  Thursday=4;
//    public final static int   Friday=5;
    /**
     * 键值对 key-Value
     */
    public static Map weekDays=new HashMap<Integer, String>();


    public static void main(String[] args) {

        System.out.println(getPreviousWeekday());
        System.out.println(getCurrentWeek());
        System.out.println(getNextMonday());

    }


    private static int weeks = 0;//


   // String[] WeekDayArray = new String[5] {""};
    /**
     * 本周一
     * @return
     */
    public static Map<Integer,String> getCurrentWeek() {


        weeks = 0;
        int mondayPlus = getMondayPlus();
        GregorianCalendar currentDate = new GregorianCalendar();
        currentDate.add(GregorianCalendar.DATE, mondayPlus);

        for(int i=0; i<5; i++) {
            int year = currentDate.get(Calendar.YEAR);
            int yue=currentDate.get(Calendar.MONTH)+1;
            int day = currentDate.get(Calendar.DAY_OF_MONTH);
            String tempMonth = (yue<10)?("0"+yue):(""+yue);
            weekDays.put(i, year+"-"+tempMonth+"-"+day);
            if(i<(5-1))    currentDate.add(Calendar.DAY_OF_MONTH, 1);
        }
//        int day0=currentDate.get(Calendar.DAY_OF_MONTH);
//        weekDays.put(Monday, year + ""+yue+"月"+day0+"日");
//
//        currentDate.add(Calendar.DAY_OF_MONTH, 1);
//        int day1=currentDate.get(Calendar.DAY_OF_MONTH);
//        weekDays.put(Tuesday, ""+yue+"月"+day1+"日");
//
//        currentDate.add(Calendar.DAY_OF_MONTH, 1);
//        int day2=currentDate.get(Calendar.DAY_OF_MONTH);
//        weekDays.put(Wednesday, ""+yue+"月"+day2+"日");
//
//        currentDate.add(Calendar.DAY_OF_MONTH, 1);
//        int day3=currentDate.get(Calendar.DAY_OF_MONTH);
//        weekDays.put(Thursday, ""+yue+"月"+day3+"日");
//
//        currentDate.add(Calendar.DAY_OF_MONTH, 1);
//        int day4=currentDate.get(Calendar.DAY_OF_MONTH);
//        date.put(Friday, ""+yue+"月"+day4+"日");

        System.out.println(weekDays.toString());

        return weekDays;
    }
    /**
     *上周一
     * @return
     */

    public static Map<Integer,String> getPreviousWeekday() {
       // Map date=new HashMap<Integer, String>();
        weeks--;

        int mondayPlus = getMondayPlus();
        GregorianCalendar currentDate = new GregorianCalendar();
        currentDate.add(GregorianCalendar.DATE, mondayPlus + 7 * weeks);//currentDate.add(GregorianCalendar.DATE, mondayPlus);

        for(int i=0; i<5; i++) {
            int year = currentDate.get(Calendar.YEAR);
            int yue=currentDate.get(Calendar.MONTH)+1;
            int day = currentDate.get(Calendar.DAY_OF_MONTH);
            String tempMonth = (yue<10)?("0"+yue):(""+yue);
            weekDays.put(i, year+"-"+tempMonth+"-"+day);
            if(i<(5-1))    currentDate.add(Calendar.DAY_OF_MONTH, 1);
        }
        return weekDays;


//        int mondayPlus = getMondayPlus();
//        GregorianCalendar currentDate = new GregorianCalendar();
//        currentDate.add(GregorianCalendar.DATE, mondayPlus + 7 * weeks);
//        int yue=currentDate.get(Calendar.MONTH)+1;
//        int day0=currentDate.get(Calendar.DAY_OF_MONTH);
//        date.put(Monday, ""+yue+"月"+day0+"日");
//
//        currentDate.add(Calendar.DAY_OF_MONTH, 1);
//        int day1=currentDate.get(Calendar.DAY_OF_MONTH);
//        date.put(Tuesday, ""+yue+"月"+day1+"日");
//
//        currentDate.add(Calendar.DAY_OF_MONTH, 1);
//        int day2=currentDate.get(Calendar.DAY_OF_MONTH);
//        date.put(Wednesday, ""+yue+"月"+day2+"日");
//
//        currentDate.add(Calendar.DAY_OF_MONTH, 1);
//        int day3=currentDate.get(Calendar.DAY_OF_MONTH);
//        date.put(Thursday, ""+yue+"月"+day3+"日");
//
//        currentDate.add(Calendar.DAY_OF_MONTH, 1);
//        int day4=currentDate.get(Calendar.DAY_OF_MONTH);
//        date.put(Friday, ""+yue+"月"+day4+"日");
//
//        System.out.println(date.toString());
//
//        return date;
    }


    /**
     * 下周一
     * @return
     */

    public static Map<Integer,String> getNextMonday() {
       // Map date=new HashMap<Integer, String>();
        weeks++;
        int mondayPlus = getMondayPlus();
        GregorianCalendar currentDate = new GregorianCalendar();
        currentDate.add(GregorianCalendar.DATE, mondayPlus + 7 * weeks);//currentDate.add(GregorianCalendar.DATE, mondayPlus);

        for(int i=0; i<5; i++) {
            int year = currentDate.get(Calendar.YEAR);
            int yue=currentDate.get(Calendar.MONTH)+1;
            int day = currentDate.get(Calendar.DAY_OF_MONTH);
            String tempMonth = (yue<10)?("0"+yue):(""+yue);
            weekDays.put(i, year+"-"+tempMonth+"-"+day);
            if(i<(5-1))    currentDate.add(Calendar.DAY_OF_MONTH, 1);
        }
//        int mondayPlus = getMondayPlus();
//        GregorianCalendar currentDate = new GregorianCalendar();
//        currentDate.add(GregorianCalendar.DATE, mondayPlus + 7*weeks);
//        int yue=currentDate.get(Calendar.MONTH)+1;
//
//        int day0=currentDate.get(Calendar.DAY_OF_MONTH);
//        date.put(Monday, ""+yue+"月"+day0+"日");
//
//        currentDate.add(Calendar.DAY_OF_MONTH, 1);
//        int day1=currentDate.get(Calendar.DAY_OF_MONTH);
//        date.put(Tuesday, ""+yue+"月"+day1+"日");
//
//        currentDate.add(Calendar.DAY_OF_MONTH, 1);
//        int day2=currentDate.get(Calendar.DAY_OF_MONTH);
//        date.put(Wednesday, ""+yue+"月"+day2+"日");
//
//        currentDate.add(Calendar.DAY_OF_MONTH, 1);
//        int day3=currentDate.get(Calendar.DAY_OF_MONTH);
//        date.put(Thursday, ""+yue+"月"+day3+"日");
//
//        currentDate.add(Calendar.DAY_OF_MONTH, 1);
//        int day4=currentDate.get(Calendar.DAY_OF_MONTH);
//        date.put(Friday, ""+yue+"月"+day4+"日");
//
//        System.out.println(date.toString());

        return weekDays;
    }





    public static int getMondayPlus() {
        Calendar cd = Calendar.getInstance();
        // 获得今天是一周的第几天，星期日是第一天，星期二是第二天......
        int dayOfWeek = cd.get(Calendar.DAY_OF_WEEK) - 1; // 因为按中国礼拜一作为第一天所以这里减1
        if (dayOfWeek == 1) {
            return 0;
        } else {
            return 1 - dayOfWeek;
        }
    }

}
